﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace DualityEngine.Business.GameModel
{
    public class AstroidField : GameModel
    {
        private List<Vector3> astroidpositions;

        public AstroidField(Vector3 position, Model model)
            : base(position, model)
        {
            astroidpositions = new List<Vector3>();
            for (int x = 0; x <= 20000; x+=5000)
            {
                for (int y = 0; y <= 20000; y+=5000)
                {
                    for (int z = 0; z <= 20000; z+=5000)
                    {
                        astroidpositions.Add(new Vector3(position.X + x, position.Y + y, position.Z + z));
                    }
                }
            }
        }

        public override void Update(GameTime gameTime)
        {
            base.Update(gameTime);
        }

        public override void Draw(GameTime gameTime)
        {
            Matrix[] transforms = new Matrix[model.Bones.Count];
            model.CopyAbsoluteBoneTransformsTo(transforms);

            foreach (Vector3 astroidposition in astroidpositions)
            {
                foreach (ModelMesh mesh in model.Meshes)
                {
                    foreach (BasicEffect effect in mesh.Effects)
                    {
                        effect.EnableDefaultLighting();
                        effect.Parameters["World"].SetValue(transforms[mesh.ParentBone.Index] * Matrix.CreateTranslation(astroidposition));
                        effect.Parameters["View"].SetValue(CameraManager.Instance.ActiveCamera.viewmatrix);
                        effect.Parameters["Projection"].SetValue(CameraManager.Instance.ActiveCamera.projectionmatrix);
                    }
                    mesh.Draw();
                }
            }
            base.Draw(gameTime);
        }
    }
}
